package com.typy.www.tpay.util;

import android.content.Context;
import android.widget.CheckBox;
import android.widget.EditText;

import java.security.Key;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 13799 on 2018/6/15.
 */

public class ParamsUtil {
    Map<String, String> params = new HashMap<>();
    Context mContext;
    public ParamsUtil() {
    }
    public Map<String, String> getParams() {
        return params;
    }

    public void put(String key, int value) {
        params.put(key, value + "");
    }

    public void put(String key, double value) {
        params.put(key, value + "");
    }

    public void put(String key, float value) {
        params.put(key, value + "");
    }

    public void put(String key, char value) {
        params.put(key, value + "");
    }

    public void put(String key, boolean value) {
        params.put(key, value + "");
    }

    public void put(String key, String value) {
        params.put(key, value);
    }

    public void put(String key, EditText editText) {
        if (editText != null && !StringUtil.isEmpty(editText.getText().toString())) {
            params.put(key, editText.getText().toString());
        }else if(editText != null){
            params.put(key, "");
        }
    }public void putDefaul(String key, EditText editText) {
        if (editText != null && !StringUtil.isEmpty(editText.getText().toString())) {
            params.put(key, editText.getText().toString());
        }else if(editText != null){
            params.put(key, "0");
        }
    }
    public void put(String key, CheckBox checkBox) {
        if (checkBox != null) {
            params.put(key, checkBox.isChecked()+"");
        }
    }
    public ParamsUtil add(String key, CheckBox checkBox) {
        if (checkBox != null) {
            params.put(key, checkBox.isChecked()+"");
        }
        return this;
    }
    public void putMd5(String key, String value) {
        if (StringUtil.isEmpty(value))
            params.put(key, "");
        else
            params.put(key, StringUtil.MD5(value));
    }
    public ParamsUtil addMd5(String key, String value) {
        if (StringUtil.isEmpty(value))
            params.put(key, "");
        else
            params.put(key, StringUtil.MD5(value));
        return this;
    }
    public void putMd5(String key, EditText editText) {
        if (editText != null && !StringUtil.isEmpty(editText.getText().toString())) {
            params.put(key, StringUtil.MD5(editText.getText().toString()));
        }else if(editText != null){
            params.put(key, "");
        }
    }
    public ParamsUtil add(String key, EditText editText) {
        if (editText != null && !StringUtil.isEmpty(editText.getText().toString())) {
            params.put(key, StringUtil.MD5(editText.getText().toString()));
        }else if(editText != null){
            params.put(key, "");
        }
        return this;
    }
}
